package 题目集.日期问题;

import java.util.Scanner;

/**
 * https://www.acwing.com/problem/content/3221/
 */
public class 日期计算 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int y = sc.nextInt();
        int d = sc.nextInt();
        int[] ints = get(y, d);
        System.out.println(ints[0]);
        System.out.println(ints[1]);
    }
    static int[] days={0,31,28,31,30,31,30,31,31,30,31,30,31};
    static int getMon(int y,int m){
        if (m==2){
            return isLeap(y)?29:28;
        }
        return days[m];
    }
    public static int[] get(int y,int total){
        int days=0;
        int m=0;
        for (int i = 1; i <= 12; i++) {
            days+=getMon(y,i);
            if (days>=total){
                m=i;
                break;
            }
        }
        int d = total - (days - getMon(y, m));
        return new int[]{m,d};
    }
    public static boolean isLeap(int y){
        return y%400==0||y%4==0&&y%100!=0;
    }
}
